package com.biz.primus.base.vo.address;

import com.biz.primus.base.enums.user.Sex;
import com.biz.primus.base.enums.user.TempAddress;
import org.apache.commons.lang3.builder.ToStringBuilder;

import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Timestamp;

/**
 * 类说明：收货地址的响应对象
 * 
 * @author xiaoyasong
 * @E-mail:yasong.xiao@biz-united.com.cn
 * @version 创建时间：2016年12月22日 上午10:36:58
 */
public class ShippingAddressVo implements Serializable, Comparable<ShippingAddressVo> {

	private static final long serialVersionUID = -6635045367530806185L;

	/**
	 * 用户ID
	 */
	private Long userId;

	/**
	 * 收货地址id
	 */
	private String id;

	/**
	 * 收货人姓名
	 */
	private String name;

	/**
	 * 收货人电话
	 */
	private String mobile;

	/**
	 * 固定电话
	 */
	private String tel;

	/**
	 * 是否为默认地址
	 */
	private Boolean isDefault;

	/**
	 * 省id
	 */
	private Integer provinceId;

	/**
	 * 市id
	 */
	private Integer cityId;

	/**
	 * 区id
	 */
	private Integer districtId;

	/**
	 * 详细地址
	 */
	private String detailAddress;

	/**
	 * 省名
	 */
	private String provinceText;

	/**
	 * 市名
	 */
	private String cityText;

	/**
	 * 区名
	 */
	private String districtText;

	/**
	 * 纬度
	 */
	private BigDecimal lat;

	/**
	 * 经度
	 */
	private BigDecimal lon;

	/**
	 * 邮编
	 */
	private String zipcode;

	/**
	 * 地址别名枚举
	 */
	private Integer addressAlias;

	/**
	 * 是否是临时收货地址
	 */
	private Integer tempAddress = TempAddress.NORMAL.getValue();

	/**
	 * 地址别名文本
	 */
	private String addressAliasText;

	/** 性别 */
	private Sex sex;

	/** 标签名称 */
	private String labelName;

	/** 标签编号 */
	private Long label;

    /**
     * 标签编号 String类型避免前端js失真
     */
	private String lableId;

	/** 最后一次使用该地址 下订单的时间，用于返回地址时 辅助排序使用 */
	private Timestamp orderTime;

	/** 老版本地址的id */
	private Long oldAddressId;

	// 距离
	private Integer distance;
	/**
	 * 送达目的地
	 */
	private String destination;

	/** 送货地址经度（相当于人的位置） */
	private BigDecimal deliverLat;

	/** 送货地址纬度（相当于人的位置） */
	private BigDecimal deliverLon;

	private Timestamp createTimestamp;

	private Timestamp updateTimestamp;

	public BigDecimal getDeliverLat() {
		return deliverLat;
	}

	public void setDeliverLat(BigDecimal deliverLat) {
		this.deliverLat = deliverLat;
	}

	public BigDecimal getDeliverLon() {
		return deliverLon;
	}

	public void setDeliverLon(BigDecimal deliverLon) {
		this.deliverLon = deliverLon;
	}

	public Integer getDistance() {
		return distance;
	}

	public void setDistance(Integer distance) {
		this.distance = distance;
	}

	public String getDestination() {
		return destination;
	}

	public void setDestination(String destination) {
		this.destination = destination;
	}

	public Boolean getDefault() {
		return isDefault;
	}

	public void setDefault(Boolean aDefault) {
		isDefault = aDefault;
	}

	public Sex getSex() {
		return sex;
	}

	public void setSex(Sex sex) {
		this.sex = sex;
	}

	public String getLabelName() {
		return labelName;
	}

	public void setLabelName(String labelName) {
		this.labelName = labelName;
	}

	public Long getLabel() {
		return label;
	}

	public void setLabel(Long label) {
		this.label = label;
	}

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public Boolean getIsDefault() {
		return isDefault;
	}

	public void setIsDefault(Boolean isDefault) {
		this.isDefault = isDefault;
	}

	public Integer getProvinceId() {
		return provinceId;
	}

	public void setProvinceId(Integer provinceId) {
		this.provinceId = provinceId;
	}

	public Integer getCityId() {
		return cityId;
	}

	public void setCityId(Integer cityId) {
		this.cityId = cityId;
	}

	public Integer getDistrictId() {
		return districtId;
	}

	public void setDistrictId(Integer districtId) {
		this.districtId = districtId;
	}

	public String getDetailAddress() {
		return detailAddress;
	}

	public void setDetailAddress(String detailAddress) {
		this.detailAddress = detailAddress;
	}

	public String getProvinceText() {
		return provinceText;
	}

	public void setProvinceText(String provinceText) {
		this.provinceText = provinceText;
	}

	public String getCityText() {
		return cityText;
	}

	public void setCityText(String cityText) {
		this.cityText = cityText;
	}

	public String getDistrictText() {
		return districtText;
	}

	public void setDistrictText(String districtText) {
		this.districtText = districtText;
	}

	public BigDecimal getLat() {
		return lat;
	}

	public void setLat(BigDecimal lat) {
		this.lat = lat;
	}

	public BigDecimal getLon() {
		return lon;
	}

	public void setLon(BigDecimal lon) {
		this.lon = lon;
	}

	public String getZipcode() {
		return zipcode;
	}

	public void setZipcode(String zipcode) {
		this.zipcode = zipcode;
	}

	public Integer getAddressAlias() {
		return addressAlias;
	}

	public void setAddressAlias(Integer addressAlias) {
		this.addressAlias = addressAlias;
	}

	public Integer getTempAddress() {
		return tempAddress;
	}

	public void setTempAddress(Integer tempAddress) {
		this.tempAddress = tempAddress;
	}

	public Timestamp getOrderTime() {
		return orderTime;
	}

	public void setOrderTime(Timestamp orderTime) {
		this.orderTime = orderTime;
	}

	public Long getOldAddressId() {
		return oldAddressId;
	}

	public void setOldAddressId(Long oldAddressId) {
		this.oldAddressId = oldAddressId;
	}

	public Timestamp getCreateTimestamp() {
		return createTimestamp;
	}

	public void setCreateTimestamp(Timestamp createTimestamp) {
		this.createTimestamp = createTimestamp;
	}

	public Timestamp getUpdateTimestamp() {
		return updateTimestamp;
	}

	public void setUpdateTimestamp(Timestamp updateTimestamp) {
		this.updateTimestamp = updateTimestamp;
	}

	public String getAddressAliasText() {
		return addressAliasText;
	}

	public void setAddressAliasText(String addressAliasText) {
		this.addressAliasText = addressAliasText;
	}

    public String getLableId() {
        return lableId;
    }

    public void setLableId(String lableId) {
        this.lableId = lableId;
    }

    public ShippingAddressFrontendVo toShippingAddressFrontendVo() {
        ShippingAddressFrontendVo vo = new ShippingAddressFrontendVo();
        vo.setUserId(this.userId.toString());
        vo.setId(this.id);
        vo.setName(this.name);
        vo.setMobile(this.mobile);
        vo.setDetailAddress(this.detailAddress);

        vo.setProvinceText(this.provinceText);
        vo.setCityText(this.cityText);
        vo.setDistrictText(this.districtText);
        vo.setProvinceId(this.provinceId);
        vo.setCityId(this.cityId);
        vo.setDistrictId(this.districtId);

        vo.setLat(this.lat);
        vo.setLon(this.lon);
        vo.setAddressAlias(this.addressAlias);
        vo.setTempAddress(this.tempAddress);

        vo.setAddressAliasText(this.addressAliasText);
        vo.setMale(true);
        if (this.sex != null && this.sex == Sex.FEMALE) {
            vo.setMale(false);
        }

        vo.setLabelName(this.labelName);
        vo.setLabel(this.label);

        vo.setOrderTime(this.orderTime);
        vo.setOldAddressId(this.oldAddressId);
        vo.setDistance(this.distance);
        vo.setDestination(this.destination);

        vo.setDeliverLat(this.deliverLat);
        vo.setDeliverLon(this.deliverLon);

        vo.setCreateTimestamp(this.createTimestamp);
        vo.setUpdateTimestamp(this.updateTimestamp);

        return vo;
    }

	@Override
	public int compareTo(ShippingAddressVo o) {
		if (o.getOrderTime() != null && this.getOrderTime() == null) {
			return 1;
		}
		if (o.getOrderTime() == null && this.getOrderTime() != null) {
			return -1;
		}
		if (o.getOrderTime() != null && this.getOrderTime() != null) {
			if (o.getOrderTime().getTime() - this.getOrderTime().getTime() > 0) {
				return 1;
			}
			return -1;
		}
		return 0;
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this).append("memberId", userId).append("id", id).append("name", name)
				.append("mobile", mobile).append("tel", tel).append("isDefault", isDefault)
				.append("provinceId", provinceId).append("cityId", cityId).append("districtId", districtId)
				.append("detailAddress", detailAddress).append("provinceText", provinceText)
				.append("cityText", cityText).append("districtText", districtText).append("lat", lat).append("lon", lon)
				.append("zipcode", zipcode).append("addressAlias", addressAlias).toString();
	}

}
